######################################
#模块概述：员工可以查看自己的个人档案
#作者：刘卓柳
#创建时间：2021.3.6
#更新时间：2021.3.15
######################################
# 导入数据库模块
import pymysql
# 导入Flask框架，这个框架可以快捷地实现了一个WSGI应用
from flask import Flask
from flask import flash
# 默认情况下，flask在程序文件夹中的templates子文件夹中寻找模块
from flask import render_template
# 导入前台请求的request模块
from flask import request,Blueprint,session
import traceback

# 传递根目录
showWI=Blueprint('showWI',__name__)

######################################
#函数概述：显示个人档案页面
######################################
@showWI.route('/showWorkerInfo', methods=['get', 'post'])
def showWorkerInfo():
    if session.get('isadminan')!='员工':
        flash("您没有此操作权限！")
        return render_template('homepage.html')
    wid=session.get('uid')
    conn = pymysql.connect(host='139.217.107.173', user='root', password='123456', db='project_training',
                           charset='utf8')
    cur = conn.cursor()
    # SQL 查询语句
    sql = "select* from workerinfo WHERE ID ='%s'" % (wid)
    cur.execute(sql)
    content = cur.fetchall()
    conn.close()
    if len(content)==0:
        flash("请创建个人的员工档案！")
        return render_template('homepage2.html')
    else:
        worker = content[0]
        name = worker[1]
        sex = worker[2]
        birthday = worker[3]
        city = worker[4]
        tel = worker[5]
        email = worker[6]
        workstate = worker[7]
        cname = worker[8]
        major = worker[9]
        school = worker[10]
        education = worker[11]
        return render_template('showWorkerInfo.html', name=name, sex=sex, birthday=birthday,
                               city=city,tel=tel,email=email, workstate=workstate,
                               cname=cname, major=major, school=school, education=education)

